package com.cocotea;

import com.cocotea.context.AutoValidStarterContext;
import com.cocotea.properties.ValidProperties;
import com.cocotea.valid.config.ValidConfig;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
@EnableConfigurationProperties(ValidProperties.class)
public class GdValidAutoConfiguration {
    @Resource
    private ValidProperties validProperties;

    @Bean
    AutoValidStarterContext autoValidStarterContext() {
        String validHandlerName = validProperties.getHandlerName();
        if (validHandlerName != null && !"".equals(validHandlerName)) {
            ValidConfig.VALID_HANDLER_CLASS = validHandlerName;
        }
        return new AutoValidStarterContext();
    }
}
